{extend name="base" /}
{block name="css"}
<style>
    .pages {
    text-align: center;
    padding: 10px 0;
}
.pages .pagination {
    display: inline-block;
}
.pages .pagination li {
    display: inline-block;
    margin: 0 5px;
}
</style>
{/block}
{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="{if $category == 0}layui-this{/if}">
                    <a href="{:url('admin/dp/article', ['category' => 0])}">工作动态</a>
                </li>
                <li class="{if $category == 1}layui-this{/if}">
                    <a href="{:url('admin/dp/article', ['category' => 1])}">政策列表</a>
                </li>
                <li><a href="{:url('admin/dp/article_add', ['category' => $category])}">添加文章</a></li>
            </ul>

            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>标题</th>
                            <th>分类</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {foreach name="articles" item="vo"}
                        <tr>
                            <td>{$vo.id}</td>
                            <td>{$vo.title}</td>
                            <td>
                                {if $vo.category == 0}
                                    <span class="layui-badge layui-bg-blue">工作动态</span>
                                {elseif $vo.category == 1}
                                    <span class="layui-badge layui-bg-orange">政策列表</span>
                                {/if}
                            </td>
                            <td>{:date('Y-m-d H:i:s', $vo.create_time)}</td>
                            <td>
                                <a href="{:url('admin/dp/article_edit',['id'=>$vo.id])}" class="layui-btn layui-btn-sm">编辑</a>
                                <a href="{:url('admin/dp/article_delete',['id'=>$vo.id])}" class="layui-btn layui-btn-sm ajax-delete">删除</a>
                            </td>
                        </tr>
                        {/foreach}
      
                        </tbody>
                    </table>
    <div class="pages">
              {$articles->render()}
</div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script>
layui.use(['layer'], function(){
    var $ = layui.jquery, layer = layui.layer;

    $('.ajax-delete').on('click', function () {
        var _href = $(this).attr('href');
        layer.confirm('确定删除该文章？', function(index){
            $.get(_href, function(info){
                if(info.code === 1){
                    location.reload();
                }
                layer.msg(info.msg);
            });
            layer.close(index);
        });
        return false;
    });
});
</script>
{/block}
